﻿using DeviceDebugger.Common;
using DeviceDebugger.Model;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DeviceDebugger.ViewModel
{
    public class MonitorViewModel : ViewModelBase
    {
        /// <summary>
        /// 关闭窗口
        /// </summary>
        public RelayCommand<Window> CloseWindowCommand => new RelayCommand<Window>(CloseWindowCommand_Click);

        private ObservableCollection<ProtocolModel> _listReadProtocol;
        public ObservableCollection<ProtocolModel> ListReadProtocol
        {
            get { return _listReadProtocol; }
            set { _listReadProtocol = value; RaisePropertyChanged(() => ListReadProtocol); }
        }

        private ObservableCollection<ProtocolModel> _listWriteProtocol;
        public ObservableCollection<ProtocolModel> ListWriteProtocol
        {
            get { return _listWriteProtocol; }
            set { _listWriteProtocol = value; RaisePropertyChanged(() => ListWriteProtocol); }
        }

        public MonitorViewModel()
        {
            if (ApplicationStore.DicProtocol != null && ApplicationStore.DicProtocol.Count > 0)
            {
                ListReadProtocol = new(ApplicationStore.DicProtocol.Values.Where(a => a.IsDisplay && a.ProtocolType == Model.Enums.ProtocolType.读取));
                ListWriteProtocol = new(ApplicationStore.DicProtocol.Values.Where(a => a.IsDisplay && a.ProtocolType == Model.Enums.ProtocolType.写入));
            }
        }

        private void CloseWindowCommand_Click(Window window)
        {
            window.Close();
        }
    }
}
